VIM Configuration

VIM 101

Created: 2022-07-21
Tags: #fleeting


local set = vim.opt

set.expandtab = true
set.smarttab = true
set.shiftwidth = 4
set.tabstop = 4

set number = true
set relativenumber = true

In nvim
Base configuration is at ~/config/nvim/init.lua

make gvim treat wrapped line as new line
gk and gj move up/down by visual line instead of text line. You could map j and k to these using

noremap j gj
noremap k gk

Some people prefer to only setup those maps for specific filetypes, in which case you'd want something like

au FileType html,tex noremap <buffer> j gj
au FileType html,tex noremap <buffer> k gk

Moving around through wrapped lines

Unlike many text editing environments,
Vim makes a distinction between displayed lines, and numbered lines. When wrap is enabled, each numbered line might be split across more than one display lines. The k and j keys move up and down by numbered lines. If you want to move the cursor up and down by display lines instead, you can use the commands gk and gj instead.

Hitting two keys in quick succession feels slow compared to pressing a single key whilst holding down a modifier key. I have the following in my .vimrc file:

vmap gj
vmap gk
vmap g
nmap g^
nmap g^

References